﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Data;
using System.Text;

public partial class Content : System.Web.UI.MasterPage
{
        public CMS.Functions fn = new CMS.Functions();
        public StringBuilder sb = new StringBuilder();
        public string LoggedInAlready = "";

        public string MetaTags
        {
            get { return Metatags.Content; }
            set { Metatags.Content = value; }
        }

        int _LiWidth;
        public int LiWidth
        {
            get { return _LiWidth; }
            set { _LiWidth = value; }
        }

        public string Jscript
        {
            get { return Jscripting.Text; }
            set { Jscripting.Text = value; }
        }

        
        public string FancyPhotoheader(Int64? UserID, String ImageUrl)
        {
            if (CMS.Functions.UserID == UserID)
            {
                return FancyPhotoHeader.ImageUrl = ImageUrl;
            }
            else
            {
                return String.Empty;
            }
        }

            
        public string Logintitle
        {
            get { return LoginTitle.Text; }
            set { LoginTitle.Text = value; }
        }


    
       public string MetaKeywords
        {
            get { return Metakeywords.Content; }
            set { Metakeywords.Content = value; }
        }

        public string PageTitle
        {
            get { return PAG_TITLE.Text; }
            set { PAG_TITLE.Text = value; }
        }


        public string SetContentHeight;

        protected void Page_Init(object sender, EventArgs e)
        {
            CMS.Functions.IsError = "";
            SetDateTime(true);
            Jscript = "";
            CMS.Rights.GetPermission(CMS.Functions.AdministrationID, CMS.Functions.UserID);

            if (!CMS.Functions.VerifyLogin.Valid && !CMS.Functions.UserID.HasValue)
            {
                Logintitle = "<div id=\"LoginHeaderText\">CMS - NEXT-GEN</div>";
            }

            if (!String.IsNullOrEmpty(CMS.Functions.Username) && !String.IsNullOrEmpty(CMS.Functions.Administrationname) && CMS.Functions.UserID.HasValue)
            {
                UserName = "Logged<a id=\"OutLog\" type=\"submit\" href=\"Login.aspx?ClearSession=1\">(out)</a>";
                Administratie = "Administration : " + "<span class=\"ColorUserName\">" + CMS.Functions.Administrationname + "</span>";
            }
            else
            {

                litAdministratie.Text = null;
                litUsername.Text = null;
            }
        }

        public string Administratie
        {
            get { return litAdministratie.Text; }
            set { litAdministratie.Text = value; }
        }


        public string UserName
        {
            get { return litUsername.Text; }
            set { litUsername.Text = value; }
        }

        void SetDateTime(Boolean Enable)
        {
            if (Enable)
            {
                Date.Text = DateTime.Now.ToShortDateString();
            }
        }

        void SetUserPicture(Boolean Visible)
        {
            if (CMS.Functions.UserID.HasValue)
            {
                var GetPicture = CMS.Uploads.GetUpload(CMS.Functions.AdministrationID, null, CMS.Functions.UserID, null, null, null).SingleOrDefault();
                if (GetPicture != null)
                {
                    string savePath = "Uploads\\Pictures\\" + CMS.Functions.Administrationname + "\\";
                    FancyPhotoHeader.ImageUrl = savePath + GetPicture.UPL_GUID + ".jpg";
                }
                else
                {
                    FancyPhotoHeader.ImageUrl = "images/NoImage.jpg";
                }
            }

            litPhotoName.Text = Visible ? "<span class=\"HeaderUserName\">" + CMS.Functions.Username + "</span>" : "";

            var aRight = CMS.Permission.GetPermission(CMS.Functions.AdministrationID, null, CMS.Functions.UserID, null, null, null,null, null).FirstOrDefault();
            if (aRight != null)
            {
                litMasterUser.Text = Visible ? String.Format("<span class=\"MasterUser\">{0}</span>", aRight.PERM_NAME) : "";
            }
            else
            {
                litMasterUser.Text = Visible ? String.Format("<span class=\"MasterUser\">{0}</span>", "") : "";
            }
            FancyPhotoHeader.Visible = Visible;
        }

        protected void FancyPhotoHeader_Click(object sender, EventArgs e)
        {
            Response.Redirect(String.Format("Users_view.aspx?UserID={0}&CMD=2", CMS.Functions.UserID));
        }


    protected void Page_Load(object sender, EventArgs e)
    {

        CMS.Functions.AuthorizeLogin(Response.Redirect);

        Log.Visible = CMS.Functions.VerifyLogin.Valid == true ? false : true;

        Menu.Visible = CMS.Functions.VerifyLogin.Valid;

        MasterAdm.Visible = CMS.Functions.IsMasterUser();

        MasterPerm.Visible = CMS.Functions.IsMasterUser();

        LoggedInAlready = CMS.Functions.VerifyLogin.Valid == true ? "hidden" : "visible";


        SetUserPicture(CMS.Functions.VerifyLogin.Valid);

        Jscripting.Text = Jscript;
    }
}
